package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/13 14:38
 * @Version 1.0
 **/
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public List<User> findAllUser() {
        List<User> all = userDao.findAllUser();
        return all;
    }

    @Override
    public Boolean login(User user, HttpSession httpSession) {
        User byUserName = userDao.findByUserName(user.getNam());
        if (byUserName==null){
            return false;
        }if (!byUserName.getPwd().equals(byUserName.getPwd())){
            return false;
        }
        httpSession.setAttribute("user",byUserName);
        return true;
    }

    @Override
    public int deleteUser(int id) {
        int i = userDao.deleteUser(id);
        return i;
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public User findUserById(int id) {
        return userDao.findUserById(id);
    }

    @Override
    public int updateUser(User user) {
        return userDao.updateUser(user);
    }
}
